package org.datascooter.inface;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.datascooter.exception.SnipManagerException;
import org.datascooter.impl.Snip;
import org.datascooter.meta.Column;
import org.datascooter.meta.MetaTable;

/**
 * Root interface for a one agent of worked with a JDBC driver, with database
 * 
 * @author nemo
 * 
 */
public interface ISnipManager {

	/*
	 * Returns a name of SnipManager combined from Datasource parameters for logging options
	 */
	public String getName();

	/**
	 * Main syncronous method for obtain data from database. To databse send Snip with request and it will be received to back with results
	 * 
	 * @param snip
	 * @return Snip
	 * @throws SnipManagerException
	 */
	public Snip retrieve(Snip snip) throws SnipManagerException;

	/**
	 * Main syncronous method for doing any operations with databse without requirement of receiving a data - it return only BigDecimal parameter for some information about execution
	 * 
	 * @param snip
	 * @throws SnipManagerException
	 */
	public void execute(Snip snip) throws SnipManagerException;

	/**
	 * Returns a current database date
	 * 
	 * @return Date
	 */
	public Date getCurrentDate();

	public IDataSource getDataSource();

	/**
	 * Free all open resources and close
	 * 
	 * @throws SQLException
	 */
	public void close();

	public void beginTransaction(String transactionId);

	/**
	 * Commits opened transaction which may be only one
	 * 
	 * @throws SnipManagerException
	 * 
	 * @throws SQLException
	 */
	public void commit() throws SnipManagerException;

	/**
	 * Rollbacks opened transaction which may be only one
	 * 
	 * @throws SnipManagerException
	 * 
	 * @throws SQLException
	 */
	public void rollback() throws SnipManagerException;

	/**
	 * Requests commint for two-phase transactions
	 */
	public void requestCommit();

	public void showSQL(boolean isShow);

	public void showRetrieveSQL(boolean isShow);

	public String getContextId();

	public boolean isTableExists(String schema, String tableName) throws SnipManagerException;

	/**
	 * Returns Map of current table columns - for verification
	 * 
	 * @param shemaName
	 * @param tableName
	 * @return Map<String, Column>
	 * @throws SnipManagerException
	 */
	public Map<String, Column> getCurrentColumns(String shemaName, String tableName) throws SnipManagerException;

	public List<MetaTable> getTables(String shemaName) throws SnipManagerException;

	public MetaTable getTableData(MetaTable table) throws SnipManagerException;

	IContextConnector getConnector();
}